<?php

	/**
	 * @see Bike_Initial
	 */
	require_once 'Bike/Initial.php';
	
	
	class Bike_Timer extends Bike_Initial
	{        static protected $_instance;

        protected $_labels = array();
        protected $_timer = array();

        static public function getInstance()
        {        	if(is_null(self::$_instance))
        	{        		self::$_instance = new self();
        	}
        	return self::$_instance;
        }

        static public function start($Label='common')
        {        	self::getInstance()->startLabel($Label);
        }

        static public function stop($Label='common')
        {
        	self::getInstance()->stopLabel($Label);
        }

        protected function getMicroTime()
        {        	return microtime(True);
        }

        protected function startLabel($Label)
        {        	$time = $this->getMicroTime();
        	array_push($this->_timer, array('Label' => $Label, 'Type' => 'Start', 'Time' =>  $time));
        	$this->_labels[$Label]['start'] = $time;
        }

        protected function stopLabel($Label)
        {
        	$time = $this->getMicroTime();
        	if(isset($this->_labels[$Label]['start']))
        	{        		$diff = ($time - $this->_labels[$Label]['start']);
        	}
        	array_push($this->_timer, array('Label' => $Label, 'Type' => 'Stop', 'Time' => $time, 'Performed' => $diff));
        }

        public function __toString()
        {        	return (string) print_r($this->_timer, true);
        }
	}
